<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='base/common_header'}
    <style>
        .layui-table td, .layui-table th { min-width: auto; }
    </style>
</head>

<body>

<br/>
<br/>
<br/>
<div class="layui-form layuimini-form">


    <form class="question-form layui-form layui-col-space10">
        <input type="hidden" name="topic_id" value="{$topic_id}">
        <input type="hidden" name="id" value="{$id}">
        <div class="layui-form-item layui-form-text">
            <label for="desc" class="layui-form-label">
                <span class="x-red">*</span>答案图片</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="share-img">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <div class="share-show" style="width: 200px;margin-top: 5px"><img src="{$data.answer_img}" style="width: auto;max-width: 100%;max-height: 100%"></div>
                <input type="hidden" value="{$data.answer_img}" name="answer_img" class="share_img">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>最小分值</label>
            <div class="layui-input-inline">
                <input type="number" id="sort" value="{$data.min_score}" name="min_score" value="0" lay-verify="required" required=""  autocomplete="off" class="sort-q layui-input">
                <div style="color: red;">只能填写正整数，在1-100之间，出错自己负责哦</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>最大分值</label>
            <div class="layui-input-inline">
                <input type="number" id="sort" value="{$data.max_score}" name="max_score" value="0" lay-verify="required" required=""  autocomplete="off" class="sort-q layui-input">
                <div style="color: red;">只能填写正整数，在1-100之间，出错自己负责哦</div>
            </div>
        </div>
         <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="add" lay-submit="">确认保存</button>
            </div>
        </div>
    </form>

</div>

</body>
<script>
    /*添加选项*/
    layui.use(['form','layer'], function () {
        var $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //监听提交
        form.on('submit(add)',
            function(data) {
                $.post("/admin/topic/saveAnswer",$('.question-form').serialize(),function (res) {
                    if(res.error_code != 0){
                        layer.msg(res.msg,{icon:5});
                    }else{
                        //发异步，把数据提交给php
                        layer.msg("操作成功", {
                                icon: 6
                            },
                            function() {
                                window.parent.location.reload();
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                            });
                    }
                },'json')
                return false;
            });


    });

    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        upload.render({
            elem: '#share-img' //绑定元素
            ,url: '/api/fileUpload' //上传接口
            ,size: 1024
            ,data:{useOrigin:1}
            ,done: function(res){
                //上传完毕回调
                if(res.code == 1){
                    $('#share-img').parents('.layui-input-block').find('.share-show').find('img').attr('src',res.photo)
                    $('#share-img').parents('.layui-input-block').find('.share_img').val(res.photo)
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('上传失败')
            }
        });
    });

</script>
</html>